import React, { Component } from "react";
import { connect } from "react-redux";
import { Toast, Portal } from "@ant-design/react-native";
import TopNavBar from "components/TopNavBar";
import WebViewDetail from "components/WebViewDetail";

import { View, ScrollView, Text } from "react-native";
import styles from "./styles";

/**
 * 详情查看页面
 */
class index extends Component {
  state = {
    showContent: "",
    curNewsDetail: {},
  };

  componentDidMount() {
    this.loadData();
  }

  /** 加载数据 */
  loadData = () => {
    const { navigation } = this.props;

    // eslint-disable-next-line prefer-const
    let content = navigation.getParam("content") || {};

    // const key = Toast.loading("数据加载中...", 0);
    // this.setState({ showContent: false });

    // Portal.remove(key);
    // content = `<p><a href="http://172.16.23.121:30866" target="_blank">单牌车</a></p><p></p><p><a href="http://172.16.23.121:30866" target="_blank">http://172.16.23.121:30866</a></p><p></p>`;
    this.setState({ showContent: true, curNewsDetail: content });
  };

  render() {
    const { navigation } = this.props;
    const { showContent, curNewsDetail } = this.state;

    if (!showContent) return null;

    return (
      <View style={styles.root}>
        <View style={styles.header}>
          <TopNavBar
            midText="扫码结果"
            navigation={navigation}
            // rightText={this.right()}
          />
        </View>

        <ScrollView showsVerticalScrollIndicator={false}>
          <View style={{ flex: 1, paddingHorizontal: 15 }}>
            {/* webview */}
            <WebViewDetail content={curNewsDetail} />
          </View>
        </ScrollView>
      </View>
    );
  }
}

export default connect()(index);
